﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title>宾果高校</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/sweetalert.min.css" />
    <script src="../js/jquery-1.12.2.min.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/login.js"></script>
    <script src="../js/angular.min.js"></script>
    <script src="../js/Controller.js"></script>
    <script src="../js/store.min.js"></script>
    <script src="../js/sweetalert.min.js"></script>
    <script>

        var params = store.get("selectParams");
        if (params == null || params == undefined) {
            window.location("select.html");
        }
        else {

            var app = angular.module('myApp2', []);

            var result;
            var resultConn = [];

            var projectID = params.ProjectNO;

            app.controller('MyCtrl', function ($http, $scope) {
                $http.post('../api/project/post/', params).success(function (data) {

                    store.clear("selectParams");

                    if (data == null)
                        window.location = "../login.html";

                    result = data.ResponseList;
                    $scope.names = data.ResponseList;

                }).error(function (data, status, headers, config) {

                    store.clear("selectParams");

                    common.alertMessage(data.Message, status);

                    //if (status == "401")
                    //    window.location = "../login.html";
                });

                $scope.add = function (id) {

                    for (var i = 0; i < result.length; i++) {
                        if (result[i].Association.AssociationNO == id) {

                            for (var i = 0; i < resultConn.length; i++) {
                                if (resultConn[i].Association.AssociationNO == id) {
                                    return;
                                }
                            }

                            resultConn.push(result[i]);
                            break;

                        }
                    }

                    var ele = document.querySelector("[ng-controller=MyCtrl1]");
                    angular.element(ele).scope().update(resultConn);
                }
            });

            app.controller('MyCtrl1', function ($http, $scope) {
                $scope.remove = function (id) {
                    for (var i = 0; i < resultConn.length; i++) {
                        if (resultConn[i].Association.AssociationNO == id) {
                            resultConn.splice(i, 1);
                            break;
                        }
                    }

                    $scope.update(resultConn);
                }

                $scope.update = function (data) {
                    $scope.names = data;
                    $scope.$apply();
                }
            });
        }

        function AfteAjax(ctx) {
            if (ctx == undefined || ctx == "")
                return;

            window.location = "contact-status.html";
        }

        function Go() {

            var temp = "";

            for (var i = 0; i < resultConn.length; i++) {
                temp += resultConn[i].ProjectNO + "$%";
            }

            common.commonAjax({ type: 'Get', url: '../api/project/ConnectAssociation?id=' + temp + "&projectID=" + projectID, sMethod: AfteAjax });
        }

    </script>
</head>
<body>
    <div id="searchPage"></div>
    <div style="margin-top: 20px;" class="main">
        <div class="wrap">
            <div class="panel panel-default">
                <div class="panel-body" ng-app="myApp2">
                    <table class="table table-hover" ng-controller="MyCtrl">
                        <tr>
                            <td>确定选择</td>
                            <td>社团名称</td>
                            <td>社团地区</td>
                            <td>社团级别</td>
                            <td>社团类型</td>
                            <td>社团星级</td>
                            <td>社团活动书</td>
                        </tr>
                        <tr ng-repeat="x in names">
                            <td>
                                <button class="btn btn-default btn-xs" ng-click="add(x.Association.AssociationNO)">确定</button>
                            </td>
                            <td>{{x.Association.Name}}</td>
                            <td>{{x.Association.ProvinceName+'-'+x.Association.CityName}}</td>
                            <td>{{x.Association.Type}}</td>
                            <td>{{x.Association.SchoolGradeName}}</td>
                            <td>{{x.Association.AssociationGrade==1?"金牌社团":x.Association.AssociationGrade==0?"普通社团":"代理社团"}}</td>
                            <td><a href="{{x.Association.AssociationNO}}">查看</a></td>
                        </tr>
                        <!--<tr>
                            <td>
                                <button class="btn btn-default btn-xs">确定</button>
                            </td>
                            <td>学生会A</td>
                            <td>广东省广州市广州大学</td>
                            <td>校级</td>
                            <td>组织类</td>
                            <td>普通社团</td>
                            <td><a href="">链接（弹框）</a></td>
                        </tr>-->
                    </table>
                    <!--<nav class="text-center">
                        <ul class="pagination">
                            <li class="active"><a href="">1</a></li>
                            <li><a href="">2</a></li>
                            <li><a href="">3</a></li>
                        </ul>
                    </nav>-->
                    <div class="selected" ng-controller="MyCtrl1">
                        <table class="table table-hover">
                            <tr>
                                <td>社团名称</td>
                                <td>社团地区</td>
                                <td>社团级别</td>
                                <td>社团类型</td>
                                <td>社团星级</td>
                                <td>社团活动书</td>
                                <td>取消</td>
                            </tr>
                            <tr ng-repeat="x in names">
                                <td>{{x.Association.Name}}</td>
                                <td>{{x.Association.ProvinceName}}{{x.Association.CityName}}</td>
                                <td>{{x.Association.Type}}</td>
                                <td>{{x.Association.SchoolGradeName}}</td>
                                <td>{{x.Association.AssociationGrade==1?"金牌社团":x.Association.AssociationGrade==0?"普通社团":"代理社团"}}</td>
                                <td><a href="">查看</a></td>
                                <td>
                                    <button class="btn btn-default btn-xs" ng-click="remove(x.Association.AssociationNO)">取消</button>
                                </td>
                            </tr>
                            <!--<tr>
                                <td>学生会A</td>
                                <td>广东省广州市广州大学</td>
                                <td>校级</td>
                                <td>组织类</td>
                                <td>普通社团</td>
                                <td><a href="">链接（弹框）</a></td>
                                <td>
                                    <button class="btn btn-default btn-xs">取消</button>
                                </td>
                            </tr>-->
                        </table>
                        <div class="text-center">
                            <button type="button" class="btn btn-default" onclick="Go()">联系社团</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
    $("#searchPage").load("header.html", function () {
        SetCss("Select");
    });
</script>